import { createStore } from 'vuex'

const store = createStore({
    state() {
        return {
            patients: [],
            // 存储token
            Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : ''
        }
    },

    mutations: {
        // 修改token，并将token存入localStorage
        setToken(state, userToken) {
            // console.log(userToken);
            state.Authorization = userToken;
            localStorage.setItem('Authorization', userToken);
        },
        clearToken(state) {
            state.Authorization = null;
            localStorage.removeItem('Authorization');
        },
    },
    actions: {
        updateToken({ commit }, userToken) {
            commit('setToken', userToken);
        },
        logout({ commit }) {
            commit('clearToken');
        }
    }
});

export default store;
